package com.buluo.service.impl

import com.buluo.service.FilmService
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import org.springframework.stereotype.Service

/**
 * Created by sunhao on 2016/12/16.
 */
@Service
class FilmServiceImpl extends BaseMongoServiceImpl implements FilmService{
    @Override
    DBCollection getColl() {
        hdMongoTemplate.getCollection("hd_films")
    }

//    @Override
//    List<String> listFilmTypes() {
//        def info = hdMongoTemplate.getCollection("hd_filmTypes").findOne([name: "hd_films"] as BasicDBObject)
//        if (info) {
//            return info.types
//        }
//        return Collections.emptyList()
//    }

    @Override
    List getAll(BasicDBObject query, BasicDBObject sort, BasicDBObject returnFiled) {
        DBCursor cursor
        if (sort) {
            cursor = getColl().find(query, returnFiled).sort(sort).batchSize(1000)
        } else {
            cursor = getColl().find(query, returnFiled).batchSize(1000)
        }

        def list = new ArrayList()
        while (cursor.hasNext()) {
            list.add(cursor.next())
        }
        return list
    }
}
